package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author hql
 * @date 2019-12-06 11:47
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    @Reference
    private SetmealService setmealService;

    /**
     * 获取所有的套餐信息
     * @return
     */
    @RequestMapping("/getAllSetmeal")
    public Result  getAllSetmeal(){
        List<Setmeal> setmealList =null;
        try {
            setmealList=setmealService.getAllSetmeal();

        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_SETMEAL_COUNT_REPORT_FAIL);
        }

        return new Result(true, MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS,setmealList);
    }

    /**
     * 获取所有的套餐信息，包括检查组信息以及检查检查项信息
     * @param id
     * @return
     */
    @RequestMapping("/findById")
    public Result  findById(Integer id){
        Setmeal setmeal=null;
        try {
         setmeal = setmealService.findById(id);

        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_SETMEAL_COUNT_REPORT_FAIL);
        }

        return new Result(true, MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS,setmeal);
    }

    /**
     * 根据id查询出对应的检查套餐
     * @param id
     * @return
     */
    @RequestMapping("/findById2")
    public Result  findById2(Integer id){
        Setmeal setmeal=null;
        try {
            setmeal = setmealService.findById2(id);

        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_SETMEAL_COUNT_REPORT_FAIL);
        }

        return new Result(true, MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS,setmeal);
    }
}
